# Copyright (C) 2013 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

exports_files([
    "dry_run_connection_handler.cc",
    "dry_run_connection_handler.h",
    "normal_connection_handler.cc",
    "normal_connection_handler.h",
    "server_connection_handler.h",
])

cc_library(
    name = "correlation_id",
    hdrs = ["correlation_id.h"],
    visibility = [
        "//flare/net:__subpackages__",
        "//flare/rpc:__subpackages__",
    ],
    deps = [
        "//flare/base:id_alloc",
    ],
)

cc_library(
    name = "correlation_map",
    hdrs = ["correlation_map.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [
        ":sharded_call_map",
        "//flare/base:id_alloc",
        "//flare/base:never_destroyed",
        "//flare/fiber",
    ],
)

cc_library(
    name = "stream_call_gate_pool",
    srcs = ["stream_call_gate_pool.cc"],
    hdrs = ["stream_call_gate_pool.h"],
    visibility = [
        "//flare:__pkg__",
        "//flare/net:__subpackages__",
        "//flare/rpc:__subpackages__",
    ],
    deps = [
        ":stream_call_gate",
        "//flare/base:exposed_var",
        "//flare/base:function_view",
        "//flare/base:hazptr",
        "//flare/base:random",
        "//flare/base:ref_ptr",
        "//flare/base/internal:early_init",
        "//flare/base/internal:hash_map",
        "//flare/base/net:endpoint",
        "//flare/base/thread:latch",
        "//flare/fiber",
        "//flare/io:io_basic",
        "@com_github_gflags_gflags//:gflags",
    ],
)

cc_test(
    name = "stream_call_gate_pool_test",
    srcs = ["stream_call_gate_pool_test.cc"],
    deps = [
        ":stream_call_gate",
        ":stream_call_gate_pool",
        "//flare/fiber",
        "//flare/rpc",
        "//flare/testing:endpoint",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "buffered_stream_provider",
    hdrs = ["buffered_stream_provider.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [
        ":stream",
        "//flare/base:logging",
        "//flare/fiber",
    ],
)

cc_test(
    name = "buffered_stream_provider_test",
    srcs = ["buffered_stream_provider_test.cc"],
    deps = [
        ":buffered_stream_provider",
        "//flare/base:maybe_owning",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "error_stream_provider",
    hdrs = ["error_stream_provider.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [":stream"],
)

cc_test(
    name = "error_stream_provider_test",
    srcs = ["error_stream_provider_test.cc"],
    deps = [
        ":error_stream_provider",
        "//flare/base:maybe_owning",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "stream_io_adaptor",
    srcs = ["stream_io_adaptor.cc"],
    hdrs = ["stream_io_adaptor.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [
        ":buffered_stream_provider",
        ":stream",
        "//flare/base:function",
        "//flare/base:maybe_owning",
        "//flare/base:ref_ptr",
        "//flare/fiber",
        "//flare/fiber:work_queue",
        "//flare/rpc/protocol:message",
    ],
)

cc_library(
    name = "sharded_call_map",
    hdrs = ["sharded_call_map.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [
        "//flare/base:align",
        "//flare/base/internal:hash_map",
    ],
)

cc_library(
    name = "rpc_metrics",
    srcs = ["rpc_metrics.cc"],
    hdrs = ["rpc_metrics.h"],
    visibility = [
        "//flare/net/hbase:__subpackages__",
        "//flare/rpc:__subpackages__",
    ],
    deps = [
        "//flare/base:never_destroyed",
        "//flare/base:write_mostly",
        "//flare/base/internal:annotation",
        "//flare/rpc/protocol/protobuf:rpc_meta_cc_proto",
        "@com_github_jsoncpp//:jsoncpp",
    ],
)

cc_test(
    name = "rpc_metrics_test",
    srcs = ["rpc_metrics_test.cc"],
    deps = [
        ":rpc_metrics",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:main",
        "@com_github_jsoncpp//:jsoncpp",
    ],
)

cc_test(
    name = "rpc_metrics_benchmark",
    srcs = ["rpc_metrics_benchmark.cc"],
    deps = [
        ":rpc_metrics",
        "//flare/testing:echo_service_proto_flare",
        "@com_github_google_benchmark//:benchmark_main",
    ],
)

cc_library(
    name = "fast_latch",
    srcs = ["fast_latch.cc"],
    hdrs = ["fast_latch.h"],
    visibility = [
        "//flare/net/hbase:__subpackages__",
        "//flare/rpc:__subpackages__",
    ],
    deps = [
        "//flare/base:callback",
        "//flare/fiber",
    ],
)

cc_test(
    name = "fast_latch_test",
    srcs = ["fast_latch_test.cc"],
    deps = [
        ":fast_latch",
        "//flare/base:random",
        "//flare/fiber",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "sampler",
    hdrs = ["sampler.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [
        "//flare/base:chrono",
        "//flare/base:likely",
        "//flare/base:logging",
        "//flare/base/thread:thread_local",
    ],
)

cc_test(
    name = "sampler_test",
    srcs = ["sampler_test.cc"],
    deps = [
        ":sampler",
        "//flare/base:chrono",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "stream_call_gate",
    srcs = ["stream_call_gate.cc"],
    hdrs = ["stream_call_gate.h"],
    visibility = [
        "//flare/net:__subpackages__",
        "//flare/rpc:__subpackages__",
    ],
    deps = [
        ":correlation_id",
        ":correlation_map",
        ":sharded_call_map",
        ":stream",
        ":stream_io_adaptor",
        "//flare/base:align",
        "//flare/base:delayed_init",
        "//flare/base:function",
        "//flare/base:maybe_owning",
        "//flare/base:object_pool",
        "//flare/base/internal:early_init",
        "//flare/base/internal:test_prod",
        "//flare/base/net:endpoint",
        "//flare/fiber",
        "//flare/io:io_basic",
        "//flare/io/native",
        "//flare/io/util:socket",
        "//flare/rpc/binlog",
        "//flare/rpc/protocol:stream_protocol",
        "@com_github_gflags_gflags//:gflags",
    ],
)

cc_test(
    name = "stream_call_gate_test",
    srcs = [],
    deps = [
        ":stream_call_gate",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "stream",
    hdrs = ["stream.h"],
    visibility = ["//flare/rpc:__subpackages__"],
    deps = [
        "//flare/base:expected",
        "//flare/base:function",
        "//flare/base:future",
        "//flare/base:ref_ptr",
        "//flare/fiber:future",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_test(
    name = "stream_test",
    srcs = ["stream_test.cc"],
    deps = [
        ":stream",
        "//flare/fiber",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "session_context",
    srcs = ["session_context.cc"],
    hdrs = ["session_context.h"],
    visibility = ["//visibility:public"],
    deps = [
        "//flare/base:object_pool",
        "//flare/base:ref_ptr",
        "//flare/fiber",
        "//flare/rpc/binlog:log_reader",
        "//flare/rpc/binlog:log_writer",
        "//flare/rpc/tracing:tracing_ops",
    ],
)
